home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / ana11 / movetrace.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  9KB  |  386 lines

  1. /*
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     *********************************************************************
  13.  */
  14.  
  15. #include "ana.h"
  16. #include "ana_glob.h"
  17. #include "graphics.h"
  18.  
  19.  
  20. public Trptr    selectedTrace = NULL;
  21.  
  22.  
  23. private    void    DeleteTrace(), SelectTrace(), MoveTraces();
  24.  
  25.  
  26. /*
  27.  * Return a pointer to the trace that contains y in its vertical position 
  28.  */
  29. public Trptr GetYTrace( y )
  30.   register Coord  y;
  31.   {
  32.     register Trptr  t;
  33.     register int    i;
  34.  
  35.     if( y >= namesBox.bot or y <= namesBox.top )
  36.     return( NULL );
  37.  
  38.     for( i = traces.disp, t = traces.first; i != 0; i--, t = t->next )
  39.       {
  40.     if( y <= t->bot )
  41.       {
  42.         return( t );
  43.       }
  44.       }
  45.     return( NULL );
  46.   }
  47.  
  48.  
  49. /*
  50.  * Underline the name of a trace, usually the selected trace.
  51.  */
  52. public void UnderlineTrace( t, color )
  53.   Trptr  t;
  54.   GC     color;
  55.   {
  56.     if( t == NULL )
  57.       return;
  58.     HLine( window, namesBox.right - 1 - t->len * CHARWIDTH, namesBox.right - 2,
  59.       (t->top + t->bot + CHARHEIGHT)/2 + 1, color );
  60.   }
  61.  
  62.  
  63. /*
  64.  * Allow the user to select a trace and move it to another position.  If the
  65.  * the new position is outside the traces height then delete that trace.
  66.  * If the trace is not moved, then it becomes the selected trace.
  67.  */
  68. public void MoveTrace( y )
  69.   Coord  y;
  70.   {
  71.     BBox         b;
  72.     XEvent       ev;
  73.     Trptr        old, new, select;
  74.     static char  delStr[] = "delete";
  75.  
  76.     if( traces.disp == 0 )
  77.     return;
  78.  
  79.     if( (select = GetYTrace( y )) == NULL )
  80.       {
  81.     XBell( display, 0 );
  82.     return;
  83.       }
  84.     old = select;
  85.  
  86.     b.top = select->top - 1;
  87.     b.right = namesBox.right - 1;
  88.     b.bot = select->bot + 1;
  89.     b.left = namesBox.left + 1;
  90.     
  91.     y = (select->bot + select->top + CHARHEIGHT) / 2;
  92.     FillAREA( window, b.left + 1, select->top,
  93.       b.right - b.left - 1, select->bot - select->top + 1, gcs.black );
  94.     StrRight( window, select->name, select->len, namesBox.right - 2, y,
  95.      gcs.white );
  96.     OutlineBox( window, b, gcs.black );
  97.  
  98.     GrabMouse( window, ButtonPressMask | ButtonMotionMask | ButtonReleaseMask,
  99.      None );
  100.  
  101.     do
  102.       {
  103.     XNextEvent( display, &ev );
  104.     if( ev.type == MotionNotify )
  105.         new = GetYTrace( ev.xmotion.y );
  106.     else if( ev.type == ButtonRelease )
  107.         new = GetYTrace( ev.xbutton.y );
  108.     else
  109.         continue;
  110.  
  111.     if( old != new )
  112.       {
  113.         if( old )
  114.         OutlineBox( window, b, gcs.white );
  115.         else
  116.         FillAREA( window, 1, timesBox.bot - CHARHEIGHT,
  117.          6 * CHARWIDTH, CHARHEIGHT+2, gcs.white );
  118.  
  119.         if( new )
  120.           {
  121.         b.top = new->top - 1;
  122.         b.bot = new->bot + 1;
  123.         OutlineBox( window, b, gcs.black );
  124.           }
  125.         else
  126.         StrLeft( window, delStr, 6, 1, timesBox.bot, gcs.white );
  127.  
  128.         old = new;
  129.       }
  130.       }
  131.      while( ev.type != ButtonRelease );
  132.  
  133.     XUngrabPointer( display, CurrentTime );
  134.     XFlush( display );
  135.  
  136.     if( old )
  137.     OutlineBox( window, b, gcs.white );
  138.     else
  139.     FillAREA( window, 1, timesBox.bot - CHARHEIGHT, 6 * CHARWIDTH,
  140.      CHARHEIGHT, gcs.white );
  141.  
  142.     FillAREA( window, b.left + 1, select->top, b.right - b.left - 1,
  143.      select->bot - select->top + 1, gcs.white );
  144.     StrRight( window, select->name, select->len, namesBox.right - 2, y,
  145.      gcs.black );
  146.  
  147.     if( select == old )
  148.     SelectTrace( select );
  149.     else if( old )
  150.       {
  151.     MoveTraces( select, old );
  152.     UnderlineTrace( selectedTrace, gcs.black );  /* select box erased it */
  153.       }
  154.     else 
  155.     DeleteTrace( select );
  156.   }
  157.  
  158.  
  159. /*
  160.  * Delete a trace from the analyzer.  Remove it from the list, dispose of the
  161.  * memory allocated to it, and redraw the required parts of the window.
  162.  */
  163. private void DeleteTrace( t )
  164.   Trptr  t;
  165.   {
  166.     int  change;
  167.  
  168.     traces.total--;
  169.     if( t == traces.first )
  170.       {
  171.     traces.first = t->next;
  172.     if( t->next )
  173.         t->next->prev = NULL;
  174.     else
  175.         traces.last = NULL;
  176.       }
  177.     else
  178.       {
  179.     t->prev->next = t->next;
  180.     if( t->next )
  181.         t->next->prev = t->prev;
  182.     else
  183.         traces.last = t->prev;
  184.       }
  185.     
  186.     if( selectedTrace == t )
  187.     selectedTrace = NULL;
  188.     Vfree( t );
  189.     traces.disp--;
  190.     change = WindowChanges();
  191.  
  192.     if( change & RESIZED )
  193.     return;
  194.  
  195.     if( not (change & NTRACE_CHANGE) )        /* no trace became visible */
  196.     SetSignalPos();
  197.  
  198.     if( change & WIDTH_CHANGE )
  199.       {
  200.     DrawScrollBar( FALSE );
  201.     RedrawTimes();
  202.       }
  203.  
  204.     RedrawNames( namesBox );
  205.     DrawCursVal( cursorBox );
  206.     DrawTraces( tims.start, tims.end );
  207.   }
  208.  
  209.  
  210. /*
  211.  * Print out information regarding the selected trace.
  212.  */
  213. private void SelectTrace( t )
  214.   Trptr  t;
  215.   {
  216.     if( t->vector )
  217.       {
  218.     if( t->n.vec->nbits > 1 )
  219.       {
  220.         PRINT( "\nvector: " );
  221.         PRINT( t->n.vec->name );
  222.         PRINTF( " bits=%d  base=%d", t->n.vec->nbits, (1 << t->bdigit) );
  223.       }
  224.     else
  225.       {
  226.         PRINT( "\nalias: " );
  227.         PRINT( t->n.vec->nodes[0]->nname );
  228.       }
  229.       }
  230.     else
  231.       {
  232.     PRINT( "\nnode: " );
  233.     PRINT( t->n.nd->nname );
  234.       }
  235.  
  236.     if( selectedTrace )
  237.     UnderlineTrace( selectedTrace, gcs.white );
  238.  
  239.     UnderlineTrace( t, gcs.black );
  240.     selectedTrace = t;
  241.   }
  242.  
  243.  
  244. /*
  245.  * Move trace 'from' to the position ocupied by trace 'to'.
  246.  */
  247. private void MoveTraces( from, to )
  248.   Trptr  from, to;
  249.   {
  250.     Trptr  tmp;
  251.     BBox   rb;
  252.  
  253.     if( to->next == from )        /* this simplifies the tests below */
  254.       {
  255.     tmp = to; to = from; from = tmp;
  256.       }
  257.  
  258.     rb.top = min( to->top, from->top );
  259.     rb.bot = max( to->bot, from->bot ) + 2;
  260.     if( from->next == to )        /* adjacent traces, swap them */
  261.       {
  262.     from->next = to->next;
  263.     to->next = from;
  264.     to->prev = from->prev;
  265.     from->prev = to;
  266.  
  267.     if( from->next )
  268.         from->next->prev = from;
  269.     else
  270.         traces.last = from;
  271.  
  272.     if( to->prev )
  273.         to->prev->next = to;
  274.     else
  275.         traces.first = to;
  276.       }
  277.     else
  278.       {
  279.     if( from->prev )
  280.         from->prev->next = from->next;
  281.     else
  282.         traces.first = from->next;
  283.  
  284.     if( from->next )
  285.         from->next->prev = from->prev;
  286.     else
  287.         traces.last = from->prev;
  288.  
  289.     if( from->top > to->top )    /* moving upwards */
  290.       {                /* insert it before 'to' */
  291.         from->next = to;
  292.         from->prev = to->prev;
  293.         if( to->prev )
  294.         to->prev->next = from;
  295.         else
  296.         traces.first = from;
  297.         to->prev = from;
  298.       }
  299.     else                /* moving downwards */
  300.       {                /* insert it after 'to' */
  301.         from->next = to->next;
  302.         from->prev = to;
  303.         to->next = from;
  304.         if( from->next )
  305.         from->next->prev = from;
  306.         else
  307.         traces.last = from;
  308.       }
  309.       }
  310.  
  311.     SetSignalPos();
  312.     rb.left = 0;
  313.     rb.right = XWINDOWSIZE;
  314.     RedrawNames( rb );
  315.     DrawCursVal( rb );
  316.     rb.left = traceBox.left;
  317.     rb.right = traceBox.right;
  318.     RedrawTraces( &rb );
  319.   }
  320.  
  321.  
  322. /*
  323.  * Allow the user to select one of the cursor values (on the right side) and
  324.  * expand it on the text window.  This is usefull for buses displayed on a
  325.  * base other that binary, as well as to find out the input status.
  326.  */
  327. public void SelectCursTrace( y )
  328.   Coord  y;
  329.   {
  330.     BBox    b;
  331.     XEvent  ev;
  332.     Trptr   new, select;
  333.  
  334.     if( traces.disp == 0 or tims.cursor < tims.first or
  335.       tims.cursor > tims.last )
  336.     return;
  337.  
  338.     b.left = cursorBox.left + 1;
  339.     b.right = cursorBox.right - 1;
  340.  
  341.     if( (select = GetYTrace( y )) )
  342.       {
  343.     b.top = select->top - 1;
  344.     b.bot = select->bot + 1;
  345.     OutlineBox( window, b, gcs.black );
  346.       }
  347.  
  348.     GrabMouse( window, ButtonPressMask | ButtonMotionMask | ButtonReleaseMask,
  349.      None );
  350.  
  351.     do
  352.       {
  353.     XNextEvent( display, &ev );
  354.     if( ev.type == MotionNotify )
  355.         new = GetYTrace( ev.xmotion.y );
  356.     else if( ev.type == ButtonRelease )
  357.         new = GetYTrace( ev.xbutton.y );
  358.     else
  359.         continue;
  360.  
  361.     if( select != new )
  362.       {
  363.         if( select )
  364.         OutlineBox( window, b, gcs.white );
  365.  
  366.         if( new )
  367.           {
  368.         b.top = new->top - 1;
  369.         b.bot = new->bot + 1;
  370.         OutlineBox( window, b, gcs.black );
  371.           }
  372.         select = new;
  373.       }
  374.       }
  375.     while( ev.type != ButtonRelease );
  376.  
  377.     XUngrabPointer( display, CurrentTime );
  378.     XFlush( display );
  379.  
  380.     if( select )
  381.       {
  382.     OutlineBox( window, b, gcs.white );
  383.     ExpandCursVal( select );
  384.       }
  385.   }
  386.